<?php
class mainMenu {

    var $article;
    var $page;
    var $pageid = null;
    var $name = null;

    function set_id($new_id) {
        $this->id = $new_id;
        return $this->id;
    }

    function set_page($new_page) {
        $this->pageid = $new_page;
        return $this->pageid;
    }

    function get_mainMenu() {
        if($_SESSION['username'] == false || $_SESSION['adminrights'] == false) {
            $level = 0;
        }
        elseif($_SESSION['username'] == true && $_SESSION['adminrights'] == false) {
            $level = 2;
        }
        elseif($_SESSION['username'] == true && $_SESSION['adminrights'] == true) {
            $level = 5;
        }

        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $result = $connect->query("SELECT id, name, parent, custom, level, hidden FROM ".$prefix."menu WHERE parent = '0' AND level <= '".$level."' AND hidden = '0' ORDER BY id");
        while($row = $result->fetch_object()) {

            if(empty($row->custom)) {
                $pageHref = $row->id;
            }
            else {
                $pageHref = $row->custom;
            }

            $this->mainMenu[] = array(
                "id" => $pageHref,
                "name" => $row->name,
                "hidden" => $row->hidden
            );
        }
        return $this->mainMenu;
        $result->close();
        $connect->close();
    }

    function get_subMenu() {
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        $result = $connect->query("SELECT id, name, parent, custom, level, hidden FROM ".$prefix."menu WHERE parent = '".$this->pageid."' AND level = '".$level."' AND hidden = '0' ORDER BY id");
        while($row = $result->fetch_object()) {

            if(empty($row->custom)) {
                $pageHref = $row->id;
            }
            else {
                $pageHref = $row->custom;
            }

            $this->subMenu[] = array(
                "id" => $pageHref,
                "name" => $row->name,
                "hidden" => $row->hidden
            );
        }
        return $this->subMenu;
        $result->close();
        $connect->close();
    }
}

?>
